<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/* nodeutil-1.0.0 (c) 2015 Kenji Urushima | kjur.github.com/jsrsasign/license
<span class='line'>  2</span>  */</span><span class="WHIT">
<span class='line'>  3</span> </span><span class="COMM">/*
<span class='line'>  4</span>  * nodeutil.js - Utilities for Node
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * version: 1.0.0 (2015 Nov 11)
<span class='line'>  7</span>  *
<span class='line'>  8</span>  * Copyright (c) 2015 Kenji Urushima (kenji.urushima@gmail.com)
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * This software is licensed under the terms of the MIT License.
<span class='line'> 11</span>  * https://kjur.github.io/jsrsasign/license/
<span class='line'> 12</span>  *
<span class='line'> 13</span>  * The above copyright and license notice shall be 
<span class='line'> 14</span>  * included in all copies or substantial portions of the Software.
<span class='line'> 15</span>  */</span><span class="WHIT">
<span class='line'> 16</span> 
<span class='line'> 17</span> </span><span class="COMM">/**
<span class='line'> 18</span>  * @fileOverview
<span class='line'> 19</span>  * @name nodeutil-1.0.js
<span class='line'> 20</span>  * @author Kenji Urushima kenji.urushima@gmail.com
<span class='line'> 21</span>  * @version 1.0.0 (2015-Nov-11)
<span class='line'> 22</span>  * @since jsrsasign 5.0.2
<span class='line'> 23</span>  * @license &lt;a href="https://kjur.github.io/jsrsasign/license/">MIT License&lt;/a>
<span class='line'> 24</span>  */</span><span class="WHIT">
<span class='line'> 25</span> 
<span class='line'> 26</span> </span><span class="COMM">/**
<span class='line'> 27</span>  * read file and return file contents as utf-8 string
<span class='line'> 28</span>  * @param {String} utf8File file name to be read
<span class='line'> 29</span>  * @return {String} utf-8 string of file contents
<span class='line'> 30</span>  * @description
<span class='line'> 31</span>  * This function only works in Node.js.
<span class='line'> 32</span>  */</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFileUTF8</span><span class="PUNC">(</span><span class="NAME">utf8File</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">readFileSync</span><span class="PUNC">(</span><span class="NAME">utf8File</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'utf8'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 36</span> 
<span class='line'> 37</span> </span><span class="COMM">/**
<span class='line'> 38</span>  * read binary file and return file contents as hexadecimal string
<span class='line'> 39</span>  * @param {String} binFile file name to be read
<span class='line'> 40</span>  * @return {String} hexadecimal string of file contents
<span class='line'> 41</span>  * @description
<span class='line'> 42</span>  * This function only works in Node.js.
<span class='line'> 43</span>  */</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFileHexByBin</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'jsrsasign'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">rs.rstrtohex</span><span class="PUNC">(</span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 49</span> 
<span class='line'> 50</span> </span><span class="COMM">/**
<span class='line'> 51</span>  * read file and return file contents
<span class='line'> 52</span>  * @param {String} binFile file name to be read
<span class='line'> 53</span>  * @return {String} raw string of file contents
<span class='line'> 54</span>  * @description
<span class='line'> 55</span>  * This function only works in Node.js.
<span class='line'> 56</span>  */</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">readFile</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">fs.readFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 61</span> 
<span class='line'> 62</span> </span><span class="COMM">/**
<span class='line'> 63</span>  * save raw string to file
<span class='line'> 64</span>  * @param {String} binFile file name to save contents.
<span class='line'> 65</span>  * @param {String} rawString string contents to be saved.
<span class='line'> 66</span>  * @description
<span class='line'> 67</span>  * This function only works in Node.js.
<span class='line'> 68</span>  */</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFile</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">    </span><span class="NAME">fs.writeFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 73</span> 
<span class='line'> 74</span> </span><span class="COMM">/**
<span class='line'> 75</span>  * save data represented by hexadecimal string to file
<span class='line'> 76</span>  * @param {String} binFile file name to save contents.
<span class='line'> 77</span>  * @param {String} hexString hexadecimal string to be saved.
<span class='line'> 78</span>  * @description
<span class='line'> 79</span>  * This function only works in Node.js.
<span class='line'> 80</span>  */</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">saveFileBinByHex</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hexString</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">fs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'fs'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">require</span><span class="PUNC">(</span><span class="STRN">'jsrsasign'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">rs.hextorstr</span><span class="PUNC">(</span><span class="NAME">hexString</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">    </span><span class="NAME">fs.writeFileSync</span><span class="PUNC">(</span><span class="NAME">binFile</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rawString</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'binary'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 87</span> </span></pre></body></html>